package pkg

import (
	"ewaimai/waimairpc/appconfig"
	"fmt"
	"github.com/smartwalle/alipay/v3"
)

//
//type Pay interface {
//	pay(OutTradeNo string, TotalAmount string)
//}
//type Alipay struct {
//	AppId      string
//	PrivateKey string
//}

//	func NewAlipay() (*Alipay, *Alipay) {
//		return &Alipay{
//			AppId:      "9021000150603294",
//			PrivateKey: "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQD11p0Y2b+QxHova1gf0lt22trwzOZfng4DhZyFCaRuFuUX2jfdEyUkfcviN1kMyIWWlf+GjXPxE6VpcxnSjPL8dcUHAEChyV+4bedS5JkWFKnPEs6/4prW5ftxX/PzpPxN3nvjgrrMpH8xkxn4AG566arjnWshz1MQux5s5D6zqC8FpunWWhv1lYPJNZQvPqWGMoyOR81tiBKXCRikvHZpnNbFg4gx0IRtUZsFPrqW6UdWh3LifXeWnGm8kCfT6JxXeRlt7kNkZ1gnvVS7Kl7b4s/ldy5t353/nR4R0xgu7bPHqBDylLIIrFyuFdhBRWNL0zmH7RYYP0eRGEbXiH5XAgMBAAECggEBAJ/lYPSC3EhKorYo+X5pEbhyjKjGfKiAYtkDlFQre1lnZsZm1qLiCux7LZsLKM5ZthnFohdf9aM9hf7aMFdz+a8e4nG1RlR0Z9/LDAQsTy2/btsSforr1o4js7GAGWnFS51SMf4+T0U/UMNrzB40Gae0R8QX5VBuSra9HgLxSZ8LZHzrJz5RlTbPeehiGvIRYgvpNSEtym7TRfsX57yvPaeA7HBOoWECqS9xVxL6e2KQ/YZ677TEKZwZkLLosao4wgwPj19cUcwcq+2wjKKpJepV8ashib65mbbudFkjhfYAbYaG0IrICdxOgPsSb5BWPBR5MHtfVLOHs3LkfuOV6xECgYEA/fuSRASCGqJ6GKZ7xl+X4eZ3ulZcvjONsHFU/qF/zMuj4lMc+6rSl5xCVE+5NhWb6xn2u2OGISsXVlkWpyPjbimHNzuEQTXlmsjsPdVfV/GmXxZf7YZDlFNYnrN7N03WBTux9268IDY3n93kY7yVnCNhX5lDD9otYPHUX0yUY5UCgYEA98p7cNQPmNKav19ue/O7WeEf5ClFTcdFPvOXql/sZmiXEuyuxpGcGkeDb5HyQUtz3lLhOnh4AIAi7Oaq1IvHdsWRVsZG4U3B/RzrSNJrfxrJhvCJFK1PVH0xlXXEMOoWNQ6k0uPfv6TJSljBPYmKXBuSphl5XZWkmlJkbsqMnzsCgYAvqeWSJDJyYyl8tMmnucrcFw9DBfATtcMSaMJlotNEELdpwuU+iZlJ4IZGIkwEzVtcbJv0IMJMOTUA/GkW5tJImzyH7gBs6Ht1Z92F4SQqcewiDiXkgnzuOhH4foBSKaZPhxtn7v0ZInOf6dlxqjN9gNpGQZHnSK+ZcOjFFa8HXQKBgEFN4+qAePvVxWLaS8vvGFk/s5/2IIW3FtDYcgg875itx+L87bL3fSSP5FvrIuWCdS8KuMEoLrgzDQFSaYNKs27h8sPjzZpjW9TRYlD2483DyYj+q6H/awDhXcf+GY6qot+o1FegJr/jNgmaCpOlRAmyWpvb6th3L8JcJIvuZdExAoGATmxhBBAEFIto1IEPDC+TsfyVlxBPkdwqFRkBswrDTP9/gQvX758EZhnr5+rRMOG+dDcyM99x6yvd65XV3e+mhr3jQi8s0OlPcfCwjT2cMciPUekOtGeQjght9+qfa8hcbXSXTbVOVlckmamBINm7phnUsVH5WLAKNbzHls1JvqU=",
//		}, nil
//
// }
func Alipay(OutTradeNo, TotalAmount string) (string, error) {
	yun := appconfig.Appconf.ALiPay
	var privateKey = yun.PrivateKey // 必须，上一步中使用 RSA签名验签工具 生成的私钥
	client, err := alipay.New(yun.AppId, privateKey, false)
	if err != nil {
		fmt.Println(err)
		return "", nil
	}
	var p = alipay.TradeWapPay{}
	p.NotifyURL = "http://xxx"
	p.ReturnURL = "https://baidu.com/"
	p.Subject = "订单金额"
	p.OutTradeNo = OutTradeNo
	p.TotalAmount = TotalAmount
	p.ProductCode = "QUICK_WAP_WAY"

	url, err := client.TradeWapPay(p)
	if err != nil {
		fmt.Println(err)
		return "", err
	}

	// 这个 payURL 即是用于打开支付宝支付页面的 URL，可将输出的内容复制，到浏览器中访问该 URL 即可打开支付页面。
	var payURL = url.String()
	return payURL, nil

}
